<?php
include_once("{$_SERVER['DOCUMENT_ROOT']}/CommonClasses/MySQLDAO.php");
include("MediaCollectionsBean.php");

class MediaCollectionsDAO extends MySQLDAO {
	protected function lookupSqlById($id) {
		switch($id) {
			case "SELECT":
				return "select id,name,coll_type_id,created_date,created_by from media_collections where id = ?";
				break;
			case "INSERT":
				return "insert into media_collections (id,name,coll_type_id,created_date,created_by) values (?,?,?,?,?)";
				break;
			case "UPDATE":
				return "update media_collections set id = ?,name = ?,coll_type_id = ?,created_date = ?,created_by = ? where id = ?";
				break;
			case "DELETE":
				return "delete from media_collections where id = ?";
				break;
			default:
				return;
				break;
		}
	}

	protected function bindParameters($id,$paramBean) {
		switch($id) {
			case "SELECT":
				$params[0] = $this->bindInt($paramBean->getId());
				break;
			case "INSERT":
				$params[0] = $this->bindInt($paramBean->getId());
				$params[1] = $this->bindString($paramBean->getName());
				$params[2] = $this->bindInt($paramBean->getCollTypeId());
				$params[3] = $this->bindDate($paramBean->getCreatedDate());
				$params[4] = $this->bindString($paramBean->getCreatedBy());
				break;
			case "UPDATE":
				break;
			case "DELETE":
				break;
		}
		return $params;
	}

	protected function loadBean($id,$row,$rows) {
		$bean = new MediaCollectionsBean();
		switch($id) {
			case "SELECT":
				$bean->setId($row['id']);
				$bean->setName($row['name']);
				$bean->setCollTypeId($row['coll_type_id']);
				$bean->setCreatedDate($row['created_date']);
				$bean->setCreatedBy($row['created_by']);
				break;
		}
		array_push($rows,$bean);
		return $rows;
	}

	protected function getDbPropertiesFile($file="") {
    	try {
			parent::getDbPropertiesFile();
        }
		catch(Exception $e) {
			print('<br><br><span style="color:red;">There was an error loading the properties file!!</span>');
	        exit();
        }
	}
}
?>
